package com.capgemini.diabeo;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


public class MealAdapter extends BaseAdapter{
	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater=null;

	public MealAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
		activity = a;
		data=d;
		inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		return data.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View vi=convertView;
		if(convertView==null)
			vi = inflater.inflate(R.layout.listview_meals, null);

		TextView titleDish = (TextView)vi.findViewById(R.id.titleDish); // title
		TextView quantiteDish = (TextView)vi.findViewById(R.id.quantiteDish); // title
		TextView glucideDish = (TextView)vi.findViewById(R.id.glucideDish); // title
		TextView igDish = (TextView)vi.findViewById(R.id.igDish); // title
		TextView lipideDish = (TextView)vi.findViewById(R.id.lipideDish); // title

		HashMap<String, String> dish = new HashMap<String, String>();
		dish = data.get(position);
		// Setting all values in listview
		titleDish.setText(dish.get(AlimentsEntry.COLUMN_NAME_NOM));
		if(!dish.get(AlimentsEntry.COLUMN_NAME_QUANTITE).isEmpty()){
			quantiteDish.setText(dish.get(AlimentsEntry.COLUMN_NAME_QUANTITE)+ " Grammes");
		}
		glucideDish.setText("Glucides : " + dish.get(AlimentsEntry.COLUMN_NAME_GLUCIDE));
		igDish.setText("IG : " + dish.get(AlimentsEntry.COLUMN_NAME_IG));
		lipideDish.setText("Lipides : " + dish.get(AlimentsEntry.COLUMN_NAME_LIPIDE));
		return vi;
	}


}
